#!/usr/bin/perl
# author: dilip@cs.berkeley.edu

# check if crond is running
my $crond_flag = 0;

open PS, "ps ax |";
while (<PS>) {	
	if ($_ =~ /crond/) {
	    $crond_flag = 1;
	} 
}

my $crontab_flag = 0;
# Check if the /etc/crontab file contains entries for periodic checking of i3 server status
open CRONTAB, "cat /etc/crontab |";
while (<CRONTAB>) {
	if ( $_ =~ /i3server_check.pl/) {
		$crontab_flag = 1;
	}
}


my $crond_rclocal_flag = 0;
# Check if /etc/rc.local starts crond on boot up.
open RCLOCAL, "cat /etc/rc.local |";
while (<RCLOCAL>) {
	if ( $_ =~ /crond/) {
		$crond_rclocal_flag = 1;
	}
}


if ( $crond_flag && $crontab_flag && $crond_rclocal_flag) {
	print "I3 monitors are running.\n";

} else {
	print "I3 montiros are not running.\n";
}


